import os
import time
import zipfile
import pandas as pd

excelName4 = '供应商总计.xlsx'


def startExcel(chengdan, gongyingshang):
    print("<<<<<<<<<<<<<<<高工报表开始计算>>>>>>>>>>>>>>>>")
    yield 10, None
    gongyingshang = pd.read_excel(gongyingshang)  # 替换为您的表格1文件路径
    yield 30, None
    chengdan = pd.read_excel(chengdan)  # 替换为您的表格1文件路径
    yield 50, None
    v = pd.merge(left=gongyingshang, right=chengdan, left_on='商品编码', right_on='商品编码_x')
    f1 = v.groupby('供货商编码').agg({'供货商实际承担费用': 'sum', '供货商名称': 'first', '销售金额': 'sum'}).reset_index()
    f2 = pd.DataFrame(f1)
    f2.to_excel(f'excel_ar/out/{excelName4}', index=False)
    yield 70, None
    zipname = f'{time.strftime("%Y%m%d%H%M%S", time.localtime())}_arzip.zip'
    with zipfile.ZipFile(f'excel_ar/out/{zipname}', 'w') as zipf:
        zipf.write(f'excel_ar/out/{excelName4}', f'{excelName4}')
    yield 100, f'baobiao/download?fileName={zipname}'
    os.remove(f'excel_ar/out/{excelName4}')
